<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>无标题文档</title>
		<script type="text/javascript" src="http://127.0.0.1/vancl_php/Static/js/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="http://127.0.0.1/vancl_php/Static/js/hdjs.min.js"></script>
		<script type="text/javascript" src="http://127.0.0.1/vancl_php/Static/uploadify/jquery.uploadify.min.js"></script>
		<link href="http://127.0.0.1/vancl_php/Static/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
		<link href="http://127.0.0.1/vancl_php/Application/Admin/View/css/style1.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="http://127.0.0.1/vancl_php/Static/css/hdjs.css" />
		<link href="http://127.0.0.1/vancl_php/Application/Admin/View/css/select.css" rel="stylesheet" type="text/css" />
		<script>
//			alert('注意,当修改商品时他的库存会被删除');
			var ajaxTypeAttr = "<?php echo U('ajaxTypeAttr');?>";
			var getGoodsAttr = "<?php echo U('getGoodsAttr');?>";
			var gid = "<?php echo $goods['gid'];?>";
			//当前的分类ID
			var cateid = "<?php echo $goods['goods_cateid'];?>";
		</script>
		<script type="text/javascript" src="http://127.0.0.1/vancl_php/Application/Admin/View/js/jquery.idTabs.min.js"></script>
		<script type="text/javascript" src="http://127.0.0.1/vancl_php/Application/Admin/View/Goods/js/editgoods.js"></script>
		<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/vancl_php/Static/ueditor/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/vancl_php/Static/ueditor/ueditor.all.min.js"></script>
		<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/vancl_php/Static/ueditor/lang/zh-cn/zh-cn.js"></script>
		<style type="text/css">
			select{
				opacity: 1;
				width:345px;
				height:35px;
				margin-bottom:5px;
				border:1px solid #999;
			}
		</style>
		<script>
			var ue = UE.getEditor('editor', {
				initialFrameWidth: 1000,
				initialFrameHeight: 400
			});
		</script>

	</head>

	<body>

		<div class="place">
			<span>位置：</span>
			<ul class="placeul">
				<li><a href="#">首页</a>
				</li>
				<li><a href="#">商品管理</a>
				</li>
				<li><a href="">添加商品</a>
				</li>
			</ul>
		</div>

		<div class="formbody">

			<div id="usual1" class="usual">

				<div class="itab">
					<ul>
						<li><a href="#tab1" class="selected">商品基础信息</a>
						</li>
						<li><a href="#tab2">商品属性</a>
						</li>
						<li><a href="#tab3">商品规格</a>
						</li>
						<li><a href="#tab4">商品详细信息</a>
						</li>
						<li><a href="#tab5">商品图册</a>
						</li>
					</ul><b style="color:red">注意：修改商品是会自动删除此商品之前的库存</b>
				</div>
				<form method="post" id="goodsForm" action="<?php echo U('subEditGoods');?>">
					<div id="tab1" class="tabson">
						<input type="hidden" name="admin_aid" value="<?php echo $hd['session']['aid'];?>" />
						<input type="hidden" name="gid" value="<?php echo $hd['get']['gid'];?>" />

						<ul class="forminfo">
							<li>
								<label>商品名<b>*</b>
								</label>
								<input name="goods_name" value="<?php echo $goods['goods_name'];?>" type="text" class="dfinput" placeholder="请输入商品名" style="width:345px;" />
							</li>
							<li>
								<label>商城价格<b>*</b>
								</label>
								<input name="shop_price" value="<?php echo $goods['shop_price'];?>" type="text" class="dfinput" placeholder="请输入商城价格" style="width:345px;" />
							</li>
							<li>
								<label>市场价</label>
								<input name="goods_market" value="<?php echo $goods['goods_market'];?>" type="text" class="dfinput" placeholder="请输入市场价" style="width:345px;" />
							</li>

							<li>
								<label>分类<b>*</b>
								</label>
								<div class="vocation">
									<select class="select1" name="goods_cateid">
										<option value="0">请选择</option>
										<?php foreach ($category as $key=>$val){?>
											<option value="<?php echo $val['cid'];?>" type_id="<?php echo $val['type_id'];?>"     <?php if($goods['goods_cateid']==$val['cid']){ ?>selected="selected"<?php } ?> ><?php echo $val['_name'];?></option>
										<?php }?>
									</select>
								</div>
								<input type="hidden" name="goods_typeid" id="goods_typeid" />
							</li>
							<!--<li>
								<label>商品状态</label>
								<label for="isok">正常
									<input name="goods_status" type="radio" value="1"  id="isok"     <?php if($goods['goods_status']==1){ ?>checked="checked"<?php } ?>>
								</label>
								<label for="isdown">下架
									<input name="goods_status" type="radio" value="0" id="isdown"     <?php if($goods['goods_status']==0){ ?>checked="checked"<?php } ?> >
								</label>
							</li>-->
							<li>
								<label>货号</label>
								<input name="goods_sn" value="<?php echo $goods['goods_sn'];?>" type="text" class="dfinput" placeholder="请输入货号" style="width:345px;" /><b>*</b>如果不输入会自动生成</li>
							<li>

								<label>品牌</label>
								<div class="vocation">
									<select class="select1" name="goods_brandid">
										<option value="0">请选择</option>
										<?php foreach ($brand as $key=>$val){?>
											<option value="<?php echo $val['bid'];?>"     <?php if($val['bid']==$goods['goods_brandid']){ ?>selected="selected"<?php } ?> ><?php echo $val['bname'];?></option>
										<?php }?>
									</select>
								</div>
							</li>

							<li>
								<label>列表图</label>
								<input name="goods_imglist" id="goods_imglist" type="file" /> 类型: *.jpg,*.png 大小: 2000KB
								<script type="text/javascript">
									$(function() {
										//异步处理上传图片
										$('#goods_imglist').uploadify({
											'formData': { //POST数据
												'<?php echo session_name();?>': '<?php echo session_id();?>',
											},
											'fileTypeDesc': '上传文件', //上传描述
											'fileTypeExts': '*.jpg;*.png',
											'swf': 'http://127.0.0.1/vancl_php/Static/uploadify/uploadify.swf',
											'uploader': '<?php echo U("uploadListImg");?>',
											'buttonText': '选择文件',
											'fileSizeLimit': '2000KB',
											'uploadLimit': 1000, //上传文件数
											'width': 65,
//											'debug':true,
											'height': 25,
											'successTimeout': 10, //等待服务器响应时间
											'removeTimeout': 0.2, //成功显示时间
											'onUploadSuccess': function(file, data, response) {
												data = $.parseJSON(data);
												var li = '';
												var input = '';
												$.each(data,function(k,v){
													input = '<input type="hidden" name="goods_listimg" value="'+v+'"/>';
													
													 li += '<li style="height:auto;float:left;width:230px;text-align:center;"><span>'
													 li += '<img src="http://127.0.0.1/vancl_php/'+v+'" width="168" height="126" /></span>';
													 li += '<h2><a href="javascript:;" >'+v+'</a></h2>';
													 li += input;
													 li += '<p><a href="javascript:;" filename="'+v+'" class="delImg">删除</a></p></li>';
												});
												//把地址放到隐藏域，这样可以提交到服务器了
												$(".goodslist").html(li);
											}
										});
									});
								</script>
							</li>
							<ul class="goodslist">
								    <?php if(!empty($goods['goods_listimg'])){ ?>
									
										<li style="height:auto;float:left;width:230px;text-align:center;"><span>
											<img src="http://127.0.0.1/vancl_php/<?php echo $goods['goods_listimg'];?>" width="168" height="126" /></span>
											<h2><a href="javascript:;" ><?php echo $goods['goods_listimg'];?></a></h2>
											<input type="hidden" name="goods_listimg" value="<?php echo $goods['goods_listimg'];?>" />
											<p><a href="javascript:;" filename="<?php echo $goods['goods_listimg'];?>" class="delListImg">删除</a>
											</p>
										</li>
										<script>
											//当点击删除列表图片按钮
											$('.delListImg').click(function(){
//												//获得当前的gid
												var $isThis = $(this);
												var filename = $(this).attr('filename');
												$.ajax({
													url:'http://127.0.0.1/vancl_php/index.php/Admin/Goods/dellistImg',
													type:'post',
													data:{gid:gid,filename:filename},
													dataType:'json',
													success:function(phpData){
														if(phpData=='1'){
															$isThis.parents('li').remove();
														}
													}
												});
											})
										</script>
									
								<?php } ?>
							</ul>
							<li>
								<label>单位</label>
								<input name="goods_unit" value="<?php echo $goods['goods_unit'];?>" type="text" class="dfinput" placeholder="请输入商品单位" style="width:345px;" />
							</li>
							<li>
								<label>点击次数</label>
								<input name="goods_click" value="<?php echo $goods['goods_click'];?>" type="text" class="dfinput" placeholder="默认点击次数" style="width:345px;" />
							</li>

							<li>
								<label>&nbsp;</label>
								<input name="" type="submit" class="btn" value="修改商品" />
							</li>
						</ul>

					</div>

					<div id="tab2" class="tabson">
						<!--遍历商品属性-->
						<ul class="forminfo goodsattr">
							<?php foreach ($typeattrs as $key=>$val){?>
								<li>
									<label><?php echo $val['attrname'];?></label>
									<div class="vocation">
										<select class="select1" name="typeattr_id[<?php echo $val['id'];?>]">
											<option value="0">请选择</option>
											<?php foreach ($val['attrvalue'] as $k=>$v){?>
												<option value="<?php echo $v;?>"     <?php if(in_array($v,$goodsAttr)){ ?>selected="selected"<?php } ?>><?php echo $v;?></option>
											<?php }?>
										</select>
									</div>
								</li>
							<?php }?>
						</ul>
						<ul class="forminfo">
							<li>
								<label>&nbsp;</label>
								<input name="" type="submit" class="btn" value="修改商品" />
							</li>
						</ul>

					</div>
					<div id="tab3" class="tabson">
						<ul class="forminfo goodsspec">
							<!--遍历商品规格 -->
							<?php foreach ($goodsSpec as $key=>$val){?>
								<li>
									<label><?php echo $val['attrname'];?></label>
									<div class="vocation">
										<select class="select1" name="spec_id[<?php echo $val['id'];?>][]">
											<option value="0">请选择</option>
											<?php foreach ($val['attrvalue'] as $k=>$v){?>
												<option value="<?php echo $v;?>"     <?php if($v==$val['attr_value']){ ?>selected="selected"<?php } ?> ><?php echo $v;?></option>
											<?php }?>
										</select>
									</div>
									<label style="margin-left:10px;">附加价格:</label>
									<input type="text" style="width:100px;margin-right:10px;" name="added_price[<?php echo $val['id'];?>][]" value="<?php echo $val['added_price'];?>" class="dfinput" /><a href="javascript:;" class="hd-btn hd-btn-primary hd-btn-sm addOne">添加规格</a>
									<a href="javascript:;" class="hd-btn hd-btn-danger hd-btn-sm delOne">删除一项</a>
								</li>
							<?php }?>
						</ul>
						<ul class="forminfo">
							<li>
								<label>&nbsp;</label>
								<input name="" type="submit" class="btn" value="修改商品" />
							</li>
						</ul>
					</div>
					<div id="tab4" class="tabson">
						<textarea id="editor" name="intro" rows="10" cols="10"><?php echo $goods['intro'];?></textarea>
						<ul class="forminfo">
							<li>
								<label>&nbsp;</label>
								<input name="" type="submit" class="btn" value="修改商品" />
							</li>
						</ul>
					</div>
					<div id="tab5" class="tabson">
						<div lab="uploadFile">
							<input id="file" type="file" multiple="true">
							<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
							<script type="text/javascript">
								$(function() {
									//异步处理上传图片
									$('#file').uploadify({
										'formData': { //POST数据
											'<?php echo session_name();?>': '<?php echo session_id();?>',
										},
										'fileTypeDesc': '上传文件', //上传描述
										'fileTypeExts': '*.jpg',
										'swf': 'http://127.0.0.1/vancl_php/Static/uploadify/uploadify.swf',
										'uploader': '<?php echo U("upload");?>',
										'buttonText': '选择文件',
										'fileSizeLimit': '2000KB',
										'uploadLimit': 1000, //上传文件数
										'width': 65,
//										'debug':true,
										'height': 25,
										'successTimeout': 10, //等待服务器响应时间
										'removeTimeout': 0.2, //成功显示时间
										'onUploadSuccess': function(file, data, response) {
											data = $.parseJSON(data);
											var li = '';
//											var str = '';
											var input = '';
											input = '<input type="hidden" name="imgs[]" value="'+data.filename+'"/>';
												li += '<li style="height:auto;"><span>'
												li += '<img src="http://127.0.0.1/vancl_php/'+data.thumb+'" width="168" height="126" /></span>';
												li += '<h2><a href="javascript:;" ></a></h2>';
												li += input;
												li += '<p><a href="javascript:;" fileext="'+data.ext+'" filename="'+data.filename+'" class="delImg">删除</a></p></li>';
											//把地址放到隐藏域，这样可以提交到服务器了
										$(".imglist").prepend(li);
										}
									});
								});
							</script>
						</div>
						<ul class="imglist">
							<?php foreach ($photo as $imgk=>$imgv){?>
								<li style="height:auto;"><span>
								<input type="hidden" name="gid" value="<?php echo $hd['get']['gid'];?>" />
								<input type="hidden" name="file" value="<?php echo $imgv;?>" />
								<img src="http://127.0.0.1/vancl_php/<?php echo $imgv;?>_medium.jpg" width="168" height="126" /></span>
									<h2><a href="javascript:;" ></a></h2>
									<p><a href="javascript:;" filename="<?php echo $imgv;?>" class="delImg">删除</a>
									</p>
								</li>
							<?php }?>
						</ul>
						<input name="" type="submit" class="btn" value="修改商品" />
					</div>
			</div>

			<script type="text/javascript">
				$("#usual1 ul").idTabs();
				$('.delImg').live('click',function(){
					$isThis = $(this);
					var imgpath = $(this).attr('filename');
					var gid = <?php echo $hd['get']['gid'];?>;
					//ajax删除那个文件  //再删除数据库中相应的那个图片数据
					$.ajax({
						url:'http://127.0.0.1/vancl_php/index.php/Admin/Goods/delImg',
						type:'post',
						data:{imgpath:imgpath,gid:gid},
						dataType:'json',
						success:function(phpData){
							if(phpData==1){
								$isThis.parents('li').remove();	
							}
						}
					})
				});
			</script>

			<script type="text/javascript">
				$('.tablelist tbody tr:odd').addClass('odd');
			
				$('#goodsForm').submit(function(){
					var isok = confirm('您确定要修改吗,修改的话会删除原有的货品库存');
			    	if(isok){
			    		return true;
			    	}
			    	return false;
   				});
		</script>


		</div>
		</form>
		<!--<form action="<?php echo U('upload');?>" method="post" enctype="multipart/form-data">
		<input type="file" name="file"  />
		<input type="submit" />
	</form>		-->

	</body>

</html>